<template>
    <div class="online">
        <!-- search -->
        <div class="search">
            <div @click="inputFocus" class="searchInput"></div>
            <i class="search-icon"></i>
            <span class="searchPlaceHolder">搜索</span>
        </div>
        <mTitle :title="title"></mTitle>
        <scroll class="online-container" :dataObj="onlineList">
            <div>
                <ul class="arts-item">
                    <li class="arts-list" v-for="(item, index) in onlineList.list" :key="index" @click.stop="handleClickOnline(item.id, item.ctype, item.sourceurl)">
                        <span class="date">{{item.createtime}}</span>
                        <h2 class="list-title">{{item.title}}</h2>
                        <img class="list-img" v-lazy="item.coverimg" alt="" />
                        <p class="desc" v-html="item.content"></p>
                        <split v-show="onlineList.list.length-1 != index"></split>
                    </li>
                    <li class="brand-list-end" v-show="endMore && onlineList.list != null">
                        <span class="text">已经到最底部啦</span>
                    </li>
                </ul>
            </div>
            <div class="no-brand" v-show="onlineList.list === null">
                <span class="text">暂无任何线上活动</span>
            </div>
        </scroll>
        <router-view></router-view>
    </div>
</template>

<script>
    import axios from 'axios'
    import mTitle from 'base/title/title'
    import Scroll from 'base/scroll/scroll'
    import Split from 'base/split/split'
    import Loading from 'base/loading/loading'

    export default {
        data () {
            return {
                title: "线上活动",
                onlineList: {},
                endMore: false
            }
        },
        methods: {
            inputFocus () {
                this.$router.push({
                    path: '/onlineSearch'
                }) 
            },
            handleClickOnline (id, flag, url) {
                if (flag === "1") {
                    this.$router.push({
                        path: '/onlineDetail/' + id
                    })
                } else {
                    window.location.href = url
                }
            },
            getOnlineInfo () {
                axios.post('/api/index.php?g=Api&m=Ucenter&a=onlineactlist', {
                    openid: localStorage.getItem("openid"),
                    mid: localStorage.getItem("memberid")
                }).then((res) => {
                    if (res.data.rescode=='0000') {
                        this.onlineList = res.data.data
                        this.endMore = true
                    }
                }).catch(function (error) {
                })
            } 
        },
        components: {mTitle,Scroll,Loading,Split},
        created () {
            this.getOnlineInfo()
        }
    }
</script>

<style lang="stylus" scoped>
    @import '~common/stylus/mixins.styl'
    
    .online
        width: 100%
        height: 100%
        position: relative
        background: #fff
        .search
            width: 100%
            height: 44px
            background: #efeff4
            padding: 0 15px
            box-sizing: border-box
            -webkit-box-sizing: border-box
            position: relative
            overflow: hidden
            .searchInput
                width: 100%
                height: 32px
                background: #fff
                margin-top: 6px
                border: none
                border-radius: 0
                padding: 0 10px
                box-sizing: border-box
                -webkit-box-sizing: border-box
            .search-icon
                position: absolute
                background: url('./search-icon.png') no-repeat
                width: 13px
                height: 13px
                background-size: 100% 100%
                top: 16px
                left: 50%
                margin-left: -15px
            .searchPlaceHolder
                font-size: 14px
                color: #979797
                position: absolute
                top: 17px
                left: 51%
        .online-container
            width: 100%
            box-sizing: border-box
            position: absolute
            top: 86px
            bottom: 0
            overflow: hidden
            .no-brand
                position: absolute
                width: 100%
                top: 50%
                -webkit-transform: translateY(-50%)
                transform: translateY(-50%)
                z-index: 9
                text-align: center
                left: 0
                right: 0
                .text
                    font-size: 20px
                    color: #0094d4
            .arts-item
                width: 100%
                .brand-list-end
                    border-top: 1px solid #eee
                    height: 40px
                    line-height: 40px
                    width: 100%
                    text-align: center
                    box-sizing: border-box
                    .text
                        color: #888
                        font-size: 14px
                .arts-list
                    width: 100%
                    position: relative
                    padding-top: 10px
                    box-sizing: border-box
                    touch-action: none
                    .date
                        font-size: 12px
                        color: #888
                        display: block
                        width: 100%
                        text-align: center
                        padding: 0 23px
                        box-sizing: border-box
                    .list-title
                        font-size: 16px
                        line-height: 130%
                        color: #000
                        margin-top: 28px
                        padding: 0 23px
                        box-sizing: border-box
                    .list-img
                        width: 100%
                        height: 180px
                        display: block
                        margin-top: 17px
                        padding: 0 23px
                        box-sizing: border-box
                    .desc
                        font-size: 14px
                        color: #888
                        margin-top: 8px
                        line-height: 150%
                        margin-bottom: 8px
                        padding: 0 23px
                        box-sizing: border-box
                        text-align: justify
</style>